package ru.slovoslovo.cropmotion.ui.filetable;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

public class TableLabelProvider extends LabelProvider implements ITableLabelProvider {
    public Image getColumnImage(Object element, int columnIndex) {
        return null;
    }
    public String getColumnText(Object element, int columnIndex) {
        File file = (File) element;
        String result = "";
        switch(columnIndex){
        case 0:
            result = FilenameUtils.getName(file.getName());
            break;
        case 1:
            result = FilenameUtils.getExtension(file.getName()).toLowerCase();
            break;
        case 2:
            result = FileUtils.byteCountToDisplaySize(file.length());
            break;
        case 3:
            result = new SimpleDateFormat("dd-MM-yyyy hh-MM-ss").format(new Date(file.lastModified()));
            break;
        default:
            //should not reach here
            result = "";
        }
        return result;
    }
}
